import request from './request'

export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}


export interface Project {
  id: number
  name: string
  description: string
  status: number
  startDate?: string
  endDate?: string
  createdAt: string
  updatedAt: string
  members: ProjectMember[]
}

export interface ProjectMember {
  id: number
  userId: number
  account: string
  name: string
  deptName?: string
  phone?: string
  email?: string
  role: string
  createdAt: string
}

export interface CreateProjectRequest {
  name: string
  description: string
  startDate?: string
  endDate?: string
}

export interface UpdateProjectRequest {
  id: number
  name: string
  description: string
  status: number
  startDate?: string
  endDate?: string
}

export interface ProjectListParams {
  keyWord?: string
  status?: number
  beginTime?: string
  endTime?: string
  pageDto: {
    pageNumber: number
    pageSize: number
  }
}

export interface PagedResult<T> {
  items: T[]
  totalCount: number
  pageNumber: number
  pageSize: number
}

// 获取项目列表
export const getProjectList = (params: ProjectListParams): Promise<ApiResponse<PagedResult<Project>>> => {
  return request.post('/project/getList', params)
}

// 创建项目
export const createProject = (data: CreateProjectRequest): Promise<any> => {
  return request.post('/project/addProject', data)
}

// 更新项目
export const updateProject = (data: UpdateProjectRequest): Promise<any> => {
  return request.post('/project/updateProject', data)
}

// 删除项目
export const deleteProject = (id: number): Promise<any> => {
  return request.post('/project/delById', { id })
}

export const getProjectInfo = (id: number): Promise<ApiResponse<Project>> => {
  return request.post('/project/getInfo', { id })
}



